package com.focus.xyz.union.pages.frontend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import org.apache.commons.lang.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Created by chenmeng on 2016/5/10.
 */
public class OrderInfoPage extends BasePage {
    private Action action;
    @FindBy(xpath = "//a[contains(text(),'查看保单')]")
    private WebElement appInfoLink;

    @FindBy(xpath = "//table[@class='insured-info-table']/tbody/tr/td[1]/div[3]")
    private WebElement orderId;
    /*订单详情页中的保单状态*/
    @FindBy(xpath = "//table[@class='insured-info-table']/tbody/tr/td[2]/div[2]/span")
    private WebElement appStatus;

    /*订单详情页中的订单状态*/
    @FindBy(xpath = "//table[@class='insured-info-table']/tbody/tr/td[2]/div[1]")
    private WebElement orderStatus;

    private String url = "http://union.xyz.cn/ordertrans/normalApp?orderInfoModel.orderIdEn";



    public OrderInfoPage(WebDriver driver, Action action) {
        super(driver, action);
        this.action = action;
        PageFactory.initElements(driver,this);
        switchTo(url);
    }

    public void linkAppInfo() throws Exception{
        if(getAppStatus().contains("已承保")){
            action.click(appInfoLink);
        }
    }

    public String getOrderId() throws Exception{
        String order = orderId.getText().trim();
        order = StringUtils.substringAfter(order,"：");
        return order;
    }

    public String getAppStatus() throws Exception{
//        return appStatus.getText().trim();
        return action.getText(By.xpath("//table[@class='insured-info-table']/tbody/tr/td[2]/div[2]/span")).trim();
    }

    public String getOrderStatus() throws Exception{
        return orderStatus.getText().trim();
    }
}
